import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressTest {
    public static void main(String[] args) {
        try {
            // 通过静态方法创建实例
            InetAddress host = InetAddress.getLocalHost();
            String hostName = host.getHostName();
            // 返回当前计算机的名称
            System.out.println(hostName);
            // 返回主机的 IP 地址
            String hostAddress = host.getHostAddress();
            System.out.println(hostAddress);
            // 本机是否可以访问
            boolean reachable = host.isReachable(1000);
            System.out.println(reachable);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
